package com.yan.demo;

import java.math.BigDecimal;

public class Demo7 {
    public static void main(String[] args) {
        // 小数运算
        BigDecimal big1 = new BigDecimal("0.1");
        BigDecimal big2 = new BigDecimal("0.2");
        System.out.println(big1.abs());
        System.out.println(big1.add(big2));
        System.out.println(big1.subtract(big2));
        System.out.println(big1.multiply(big2));
        System.out.println(big1.divide(big2));
        System.out.println(big1.remainder(big2));
        BigDecimal[] bigDecimals = big1.divideAndRemainder(big2);
        System.out.println("bigDecimals = " + bigDecimals[0]);
        System.out.println("bigDecimals = " + bigDecimals[1]);
        // 控制小数
        BigDecimal big3 = new BigDecimal("123.123456789");
        // 123.12
        System.out.println(big3.divide(new BigDecimal("1"), 2, BigDecimal.ROUND_DOWN));


    }
}
